package GUI.almacen;

import items.AlmacenContenedor;
import items.Item;

import java.awt.BorderLayout;
import java.awt.GridLayout;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;

import javax.swing.JDialog;
import javax.swing.JPanel;
import javax.swing.JScrollPane;
import javax.swing.JTextArea;
import javax.swing.ScrollPaneConstants;
import javax.swing.border.TitledBorder;

public class DialogoArticulosInforme extends JDialog implements ActionListener {
 
	private static final long serialVersionUID = 1L;
	private static final String IMPRIMIR="Imprimir";
	
	private AlmacenContenedor _listado;
	private JTextArea _areaTexto;
	private Boton _btnImprimir;
	
	public DialogoArticulosInforme( AlmacenContenedor lista) {
	 
		this._listado=lista;
		this.getContentPane().setLayout(new BorderLayout());
		
		JPanel panelPrincipal=new JPanel();
		panelPrincipal.setBorder(new TitledBorder("Informe de Almacen"));
		_areaTexto= new JTextArea("",30,32);
		_areaTexto.setEditable(false);
		JScrollPane scroll= new JScrollPane(_areaTexto);
		scroll.setVerticalScrollBarPolicy(ScrollPaneConstants.VERTICAL_SCROLLBAR_ALWAYS);
		panelPrincipal.add(scroll,BorderLayout.NORTH);
		this.getContentPane().add(panelPrincipal,BorderLayout.CENTER);
		pintar_general();
		
		JPanel panelBotones= new JPanel();
		panelBotones.setLayout(new GridLayout(1,0));
		
		_btnImprimir=new Boton("Imprimir");
		_btnImprimir.setActionCommand("Imprimir");
		_btnImprimir.addActionListener(this);
		 panelBotones.add(_btnImprimir);		

 
		this.getContentPane().add(panelBotones,BorderLayout.SOUTH);
		 
		configurar_dialogo();
	}
	
 
private void pintar_general( ){
		for(int i=0; i<_listado.dame_la_lista().size();i++){
			Item item= _listado.dame_la_lista().get(i);
					int id= item.getID();
					String identificador= Integer.toString(id);
					_areaTexto.append(identificador+"\n");
					_areaTexto.append(item.getNombre().toString()+"\n");
					_areaTexto.append(item.getDescripcion().toString()+"\n");
					_areaTexto.append(item.getMarca().toUpperCase()+"\n");
					_areaTexto.append("-------------------------------------"+"\n"); 
				}
		}
 

	private void configurar_dialogo(){
		this.setTitle("Almacen - Buscar");
		this.pack();
		this.setResizable(false);
		this.setLocationRelativeTo(null);
		this.setDefaultCloseOperation(javax.swing.WindowConstants.DISPOSE_ON_CLOSE);
		this.setModal(true);

	}
 

	@Override
	public void actionPerformed(ActionEvent e) {
		 if(e.getActionCommand().equalsIgnoreCase(IMPRIMIR)){
			 
		 }
	}
}
